﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WPFMultitouchDemo
{
    /// <summary>
    /// Interaction logic for CalibrationWindow.xaml
    /// </summary>
    public partial class CalibrationWindow : Window
    {
        private bool topright = false,
            bottomleft = false,
            bottomright = false,
            done = false;

        Point pointTopLeft = new Point(),
            pointTopRight = new Point(),
            pointBottomLeft = new Point(),
            pointBottomRight = new Point();

        public CalibrationWindow()
        {
            InitializeComponent();
        }

        private void btnCalibrate_click(object sender, RoutedEventArgs e)
        {
            if (topright)
            {
                pointTopRight = this.PointToScreen(Mouse.GetPosition(this));
                topright = false;
                bottomleft = true;
                MoveTo(btnCalibrate, double.NaN, 0, double.NaN, 0);
            }
            else if (bottomleft)
            {
                pointBottomLeft = this.PointToScreen(Mouse.GetPosition(this));
                bottomleft = false;
                bottomright = true;
                MoveTo(btnCalibrate,double.NaN , double.NaN, 0, 0);
            }
            else if (bottomright)
            {
                pointBottomRight = this.PointToScreen(Mouse.GetPosition(this));
                done = true;
            
            }
            else
            {
                pointTopLeft = this.PointToScreen(Mouse.GetPosition(this));
                topright = true;
                MoveTo(btnCalibrate, 0, double.NaN, 0, double.NaN);
            }

            if (done)
            {
                Calibrate();
                this.Close();
            }
           

        }

        private void Calibrate()
        {
       } 

        private void MoveTo(UIElement elem, double top, double left, double right, double bottom)
        {
                Canvas.SetTop(elem, top);
                Canvas.SetBottom(elem, bottom);
                Canvas.SetRight(elem, right);
                Canvas.SetLeft(elem, left);
        }
    }
}
